// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async remoteList({ state: { API, MAP, DICT, param }, getters }) {
    const { quotaCategory: category, energyType: type } = param

    const TIP = API.transTip(MAP.tipList)
    const [total, list] = await API.getList(param, TIP)

    // 整体定额
    if (category === DICT.TAB[0][0]) {
      const arr = DICT.TYPE.map(([type]) => list.find((item) => item.type === type) || { type })
      return [arr.length, arr]
    }

    // 区域定额
    if (category === DICT.TAB[1][0]) {
      if (total) return [total, list]

      const arr = getters['area/selectDict'].filter((item) => item[2] === type).map(([id]) => ({ entityId: id, type }))
      return [arr.length, arr]
    }

    return [0, []]
  },
}
